<?php
/**
 * @package		Joomla.Site
 * @copyright	Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

// Set flag that this is a parent file.
define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);

if (file_exists(dirname(__FILE__) . '/defines.php')) {
	include_once dirname(__FILE__) . '/defines.php';
}

if (!defined('_JDEFINES')) {
	define('JPATH_BASE', dirname(__FILE__));
	require_once JPATH_BASE.'/includes/defines.php';
}

require_once JPATH_BASE.'/includes/framework.php';

// Mark afterLoad in the profiler.
JDEBUG ? $_PROFILER->mark('afterLoad') : null;

// Instantiate the application.
$app = JFactory::getApplication('site');

// Initialise the application.
$app->initialise();

// Mark afterIntialise in the profiler.
JDEBUG ? $_PROFILER->mark('afterInitialise') : null;

// Route the application.
$app->route();

// Mark afterRoute in the profiler.
JDEBUG ? $_PROFILER->mark('afterRoute') : null;

// Dispatch the application.
$app->dispatch();

// Mark afterDispatch in the profiler.
JDEBUG ? $_PROFILER->mark('afterDispatch') : null;

// Render the application.
$app->render();

// Mark afterRender in the profiler.
JDEBUG ? $_PROFILER->mark('afterRender') : null;

// Return the response.
echo $app;

// dunglt  add
function getArticles($catid) {
	$app			= JFactory::getApplication();
	$appParams = $app->getParams();
	//$categories = JModel::getInstance('Categories', 'ContentModel', array('ignore_request' => true));
	//$categories->setState('filter.parentId', 14);
	//$categories->setState('params', $appParams);
	
	// Access filter
	$access = !JComponentHelper::getParams('com_content')->get('show_noauth');
	$authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));							
	
	@JModel::addIncludePath(JPATH_ROOT.'/components/com_content/models', 'Articles');
	//JTable::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_messages/tables');
	$articles = JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
	
	if($articles) {
		$articles->setState('params', $appParams);
		$articles->setState('filter.category_id', $catid);
		$articles->setState('filter.published', 1);
		$articles->setState('filter.access', $access);
		$articles->setState('list.ordering', 'a.ordering');
		$articles->setState('list.direction', 'ASC');					
		$articles->setState('filter.language', $app->getLanguageFilter());	
		//print_r($articles);	
		$items = $articles->getItems();
		return $items; 
	}
	
}
function getArticle($id) {
	$app			= JFactory::getApplication();
	$appParams = $app->getParams();
	//$categories = JModel::getInstance('Categories', 'ContentModel', array('ignore_request' => true));
	//$categories->setState('filter.parentId', 14);
	//$categories->setState('params', $appParams);
	
	// Access filter
	$access = !JComponentHelper::getParams('com_content')->get('show_noauth');
	$authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));							
	
	JModel::addIncludePath(JPATH_ROOT.'/components/com_content/models', 'Articles');
	//JTable::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_messages/tables');
	
	$article = JModel::getInstance('Article', 'ContentModel', array('ignore_request' => true));
	
	//$articles = JModel::getInstance('Article', 'ContentModel', array('ignore_request' => true));
	
	if($article) {		
		$article->setState('params', $appParams);
		$article->setState('filter.published', 1);
		$article->setState('article.id', (int) $id);
		$item = $article->getItem();
		return $item;
		/*
		$articles->setState('params', $appParams);
		$articles->setState('filter.id', $id);
		$articles->setState('filter.published', 1);
		$articles->setState('filter.access', $access);
		$articles->setState('list.ordering', 'a.ordering');
		$articles->setState('list.direction', 'ASC');					
		$articles->setState('filter.language', $app->getLanguageFilter());	
		//print_r($articles);	
		$item = $articles->getItem();
		return $item; 
		*/
	}
}
//end dunglt